/*Copyright (c) 2007 Adobe Systems Incorporated

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

/**
 * ShadowedTextButton
 * 
 * This component extends Button and places a shadow on its label. If you
 * give the Button a DropShadowFilter it will apply to the button graphic,
 * not to the label.
 * 
 * Styles:
 * 	labelShadowDistance		The distance of the shadow from the label (default is 3) 2
 * 	labelShadowColor		The color of the shadow (default is black)
 * 	labelShadowAngle		The offset of the shadow (default is 30) in degrees  45
 *	labelShadowAlpha		The initial alpha of the shadow (default is 0.65). 0.7
 * 
 */
package com.sodimac.v2s.view.components
{
	import mx.controls.Button;
	import flash.filters.DropShadowFilter;

	[Style(name="labelShadowDistance",type="Number",inherit="no")]
	[Style(name="labelShadowColor",type="Number",format="Color",inherit="no")]
	[Style(name="labelShadowAngle",type="Number",inherit="no")]
	[Style(name="labelShadowAlpha",type="Number",inherit="no")]
	
	public class ShadowedTextButton extends Button
	{
		public function ShadowedTextButton()
		{
			super();
		}
		
		/**
		 * commitProperties (override)
		 * 
		 * Applies the shadow to the label according to the styles.
		 */
		override protected function commitProperties():void
		{
			if( textField )
			{
				var distance:Number = getStyle("labelShadowDistance");
				if( isNaN(distance) ) distance = 2;
				var color:Number = getStyle("labelShadowColor");
				if( isNaN(color) ) color = 0;
				var angle:Number = getStyle("labelShadowAngle");
				if( isNaN(angle) ) angle = 45;
				var alpha:Number = getStyle("labelShadowAlpha");
				if( isNaN(alpha) ) alpha = .7;
				textField.filters = [ new DropShadowFilter(distance,angle,color,alpha,2,2) ];
			}
		}
		
		/**
		 * styleChanged (override)
		 * 
		 * Detects when a style has changed programmatically. If the style is one of
		 * the labelShadow styles, invalidateProperties() is called to have the shadow
		 * re-applied by commitProperties().
		 */
		override public function styleChanged(styleProp:String):void
		{
			super.styleChanged(styleProp);
			
			if( styleProp && styleProp.indexOf("labelShadow") == 0 ) {
				invalidateProperties();
			}
		}
	}
}